package com.hbase_mapreduce.read;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

import java.io.IOException;

public class MyMapper extends TableMapper<Text, IntWritable> {

    private Text mkey = new Text();
    private final static IntWritable mval = new IntWritable(1);

    @Override
    protected void map(ImmutableBytesWritable key, Result result, Context context) throws IOException, InterruptedException {
        String id = Bytes.toString(result.getRow());
        String clazz = Bytes.toString(result.getValue("info".getBytes(), "clazz".getBytes()));
        mkey.set(clazz);
        System.out.println("id:" + id + ",clazz:" + clazz);
        context.write(mkey, mval);
    }
}
